1. /* scfcpown.cpp by K.Tsuru */
  2. // function ID = 9103
  3. /********************************
  4. SComplex class
  5. It returns z^n.
  6. *********************************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. SComplex Cpow(const SComplex& z, int n){
  11. SComplex y(1.0), r;
  12. if( z.IsZero(9103) ){// 0^n
  13. SNManager::SetError(SNManager::DOMAIN_ERR, "Cpow z=0", 9103);
  14. }
  15. if(n == 0) return y; // 1.0
  16. if(n < 0){
  17. r = y/z; // y = 1, "1/z" is an error.
  18. n = -n;
  19. }else r = z;
  20. while(1){
  21. if(n % 2) y *= r;
  22. n /= 2;
  23. if( !n ) break;
  24. r *= r;
  25. }
  26. return y;
  27. }

scfcpown.cpp : last modifiled at 2015/06/29 16:18:10(570 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).